package logic

import (
	"context"
	"errors"
	"user_srv/models/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseReleaseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseReleaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseReleaseLogic {
	return &HouseReleaseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseReleaseLogic) HouseRelease(in *user.HouseReleaseRequest) (*user.HouseReleaseResponse, error) {
	// todo: add your logic here and delete this line
	house := mysql.House{
		HouseName:     in.HouseName,
		HouseFloor:    in.HouseFloor,
		HouseType:     in.HouseType,
		Address:       in.Address,
		HouseCover:    in.HouseCover,
		Area:          in.Area,
		Price:         in.Price,
		HouseDescribe: in.HouseDescribe,
	}
	if house.ID != 0 {
		logx.Info("房源信息不存在")
		return nil, errors.New("房源信息不存在")
	}
	err := house.Create()
	if err != nil {
		logx.Info("创建房源发布失败", err)
		return nil, errors.New("创建房源发布失败")
	}
	return &user.HouseReleaseResponse{
		HouseId: int64(house.ID),
	}, nil
}
